#include "PhoneNumberValidator.h"

PhoneNumberValidator::PhoneNumberValidator(const QString& field):NumberValidator(field,0,9999999999,true)
{

}

PhoneNumberValidator::~PhoneNumberValidator(void)
{
}

void PhoneNumberValidator::setOther(const QString& other,int max)
{
	this->other = other;
	this->otherMax = max;
}

void PhoneNumberValidator::setThis(int max)
{
	this->thisMax = max;
}

int PhoneNumberValidator::validate(QString& input)
{
	if(input.isEmpty() && other.isEmpty())
		return 0;
	int r = NumberValidator::validate(input);
	int r2 = NumberValidator::validate(other);
	if( r2 == -2)
		return -2;
	if(r == -2)
		return -3;

	if(r + r2 != 0)
		return -1;
	if(other.length() != otherMax || input.length() != thisMax)
	{
		return -5;
	}
	return 0;
}